package algorithm.recursionAndbacktrack.combination.p17;

import java.util.ArrayList;
import java.util.List;

/**
 * 17. 电话号码的字母组合
 */
class Solution_v1 {
    private String[] numLettersArray = {" ", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> letterCombinations(String digits) {
        ArrayList<String> res = new ArrayList<>();
        if (digits.length() > 0) {
            letterCombinations(res, digits, 0, "");
        }
        return res;
    }

    public void letterCombinations(ArrayList<String> res, String digits, int index, String s) {
        if (index == digits.length()) {
            res.add(s);
            return;
        }
        String numLetters = numLettersArray[digits.charAt(index) - '0'];
        for (int i = 0; i < numLetters.length(); i++) {
            letterCombinations(res, digits, index + 1, s + numLetters.charAt(i));
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution_v1().letterCombinations("23"));
    }
}